/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007-2008 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.projects.csv.bean.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.util.StringUtils;

import com.genia.toolbox.projects.csv.bean.Binder;
import com.genia.toolbox.projects.csv.bean.MutableBinder;
import com.genia.toolbox.projects.csv.bean.MutableEntityDescriptor;

/**
 * implementation of {@link MutableEntityDescriptor}.
 */
public class EntityDescriptorImpl
    extends AbstractFolderDescriptorLinkableImpl
    implements MutableEntityDescriptor
{

  /**
   * the name of the entity.
   */
  private String name;

  /**
   * the class of the entity.
   */
  private Class<?> entityClass;

  /**
   * the entity must already exist.
   */
  private Boolean createIfNull = true;

  /**
   * wether this entity must be unique in the environment.
   */
  private Boolean unique = false;

  /**
   * the list of {@link Binder} to retrieve the entity.
   */
  private List<Binder> binders = new ArrayList<Binder>();

  /**
   * if this value is <code>true</code> and a <code>null</code> entity is
   * generated for a CSV line, the line will be considered an error that will be
   * returned.
   */
  private Boolean errorIfNull = false;



  /**
   * add a {@link Binder} to the list.
   * 
   * @param binder
   *          the {@link Binder} to add
   */
  public void addBinder(MutableBinder binder)
  {
    this.binders.add(binder);
    binder.setEntityDescriptor(this);
  }



  /**
   * getter for the binders property.
   * 
   * @return the binders
   */
  public List<Binder> getBinders()
  {
    return binders;
  }



  /**
   * setter for the binders property.
   * 
   * @param binders
   *          the binders to set
   */
  public void setBinders(List<Binder> binders)
  {
    this.binders = binders;
  }



  /**
   * getter for the name property.
   * 
   * @return the name
   */
  public String getName()
  {
    return name;
  }



  /**
   * setter for the name property.
   * 
   * @param name
   *          the name to set
   */
  public void setName(String name)
  {
    this.name = StringUtils.trimWhitespace(name);
  }



  /**
   * getter for the entityClass property.
   * 
   * @return the entityClass
   */
  public Class<?> getEntityClass()
  {
    return entityClass;
  }



  /**
   * setter for the entityClass property.
   * 
   * @param entityClass
   *          the entityClass to set
   */
  public void setEntityClass(Class<?> entityClass)
  {
    this.entityClass = entityClass;
  }



  /**
   * getter for the unique property.
   * 
   * @return the unique
   */
  public Boolean getUnique()
  {
    return unique;
  }



  /**
   * setter for the unique property.
   * 
   * @param unique
   *          the unique to set
   */
  public void setUnique(Boolean unique)
  {
    this.unique = unique;
  }



  /**
   * getter for the createIfNull property.
   * 
   * @return the createIfNull
   */
  public Boolean getCreateIfNull()
  {
    return createIfNull;
  }



  /**
   * setter for the createIfNull property.
   * 
   * @param createIfNull
   *          the createIfNull to set
   */
  public void setCreateIfNull(Boolean createIfNull)
  {
    this.createIfNull = createIfNull;
  }



  /**
   * getter for the errorIfNull property.
   * 
   * @return the errorIfNull
   */
  public Boolean getErrorIfNull()
  {
    return errorIfNull;
  }



  /**
   * setter for the errorIfNull property.
   * 
   * @param errorIfNull
   *          the errorIfNull to set
   */
  public void setErrorIfNull(Boolean errorIfNull)
  {
    this.errorIfNull = errorIfNull;
  }

}
